import MySQLdb
import numpy as np

def test_pymysql1():
    conn = MySQLdb.connect(
        host = 'localhost',
        port = 3306,
        user = 'root',
        passwd = '',
        db = 'test'
    )
    cur = conn.cursor()
    cur.execute('''
            create table price (
                timestamp timestamp not null,
                btcusd float(8, 2),
                primary key (timestamp)
            );
    ''')
    cur.execute('''
            insert into price values(
                "2019-07-14 14:12:17",
                11234.56
            );
    ''')
    conn.commit()
    conn.close()

test_pymysql1()

def test_pymysql2():
    conn = MySQLdb.connect(
        host = 'localhost',
        port = 3306,
        user = 'root',
        passwd = '',
        db = 'mysql'
    )
    cur = conn.cursor()
    cur.execute('''
            select btcusd from price where
            timestamp > now() - interval 60 minute
    ''')
    btcusd = np.array(cur.fetchall())
    print(btcusd.max(), btcusd.min())
    conn.close()

test_pymysql2()